package com.haoshuang.zhouzhoubang.ui.page.study

import android.os.Bundle
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.FragmentStudyBinding
import com.haoshuang.zhouzhoubang.ui.adapter.ViewPagerAdapter
import com.haoshuang.zhouzhoubang.ui.page.study.child.StudyChildFragment
import com.haoshuang.zhouzhoubang.ui.page.study.train.TrainExamVpFragment
import com.lnkj.jialubao.utils.AccountUtils
import com.mufeng.libs.base.BaseVMFragment
import com.mufeng.libs.utils.toast
import com.qw.curtain.lib.Curtain
import com.qw.curtain.lib.shape.RoundShape


/**
 *
 */
class StudyFragment : BaseVMFragment<StudyViewModel, FragmentStudyBinding>() {

    companion object {
        fun getInstance(): StudyFragment {
            val fragment = StudyFragment()
            fragment.arguments = Bundle().apply {

            }
            return fragment
        }
    }

    private val fragments = arrayListOf<Fragment>()

    override fun initView(savedInstanceState: Bundle?) {
        fragments.clear()
        fragments.add(StudyChildFragment.getInstance(1))
        fragments.add(StudyChildFragment.getInstance(2))
        fragments.add(StudyChildFragment.getInstance(3))
        fragments.add(StudyChildFragment.getInstance(4))
        fragments.add(TrainExamVpFragment.getInstance())

        val adapter = ViewPagerAdapter(childFragmentManager, lifecycle, fragments)
        binding.viewPager.adapter = adapter
        binding.viewPager.offscreenPageLimit = 5
        binding.slidingTabLayout.setViewPager2(binding.viewPager, arrayListOf("官方公告", "新手指南", "服务技巧", "规范手册", "培训考试"))

    }

    private fun showGuide(){
        val view = binding.slidingTabLayout.getChildAt(0)
        if (view is ViewGroup){
            val item = view.getChildAt(4)
            Curtain(mActivity)
                .with(item)
                .withShape(item, RoundShape(12f))
                .setTopView(R.layout.guide_study1)
                .addOnTopViewClickListener(R.id.tvNext){ current, host ->
                    AccountUtils.studyStep1Guide = true
                    host.dismissGuide()
                    binding.viewPager.currentItem = 4
                }
                .show()
        }


    }

    override fun initData() {

    }

    override fun lazyLoadData() {
        if (!AccountUtils.studyStep1Guide) {
            showGuide()
        }
    }

    override fun startObserve() {

    }

}